import time

from config.config import Base
from selenium.webdriver.common.by import By


class Page(Base):
    # 登录
    login_loc = (By.CLASS_NAME, 'headerLogin')

    def login(self):
        self.click(self.login_loc)

    # 断言
    dy1_loc = (By.XPATH, '/html/body/div[1]/form/div/div/div/div/div[1]/div[1]/a[1]')

    def dy1(self):
        return self.text(self.dy1_loc)

    # 输入用户名和密码
    username_loc = (By.NAME, 'uname')

    def username(self):
        self.send_keys(self.username_loc, '18790225065')

    password_loc = (By.NAME, '_pwd')

    def password(self):
        self.send_keys(self.password_loc, 'duanmengna0225@')

    # 点击登录
    denglu_loc = (By.ID, 'save')

    def denglu(self):
        self.click(self.denglu_loc)

    # 点击确定
    queding_loc = (By.XPATH, '//*[@id="bindSub"]')

    def queding(self):
        self.click(self.queding_loc)

    # 点击输入框
    ssk_loc = (By.ID, 'wd')

    def ssk(self):
        self.click(self.ssk_loc)

    # 输入文字
    wenzi_loc = (By.ID, 'wd')

    def wenzi(self):
        self.send_keys(self.wenzi_loc, '剑南春')

    # 点击按钮
    anniu_loc = (By.CLASS_NAME, 'search-btn')

    def anniu(self):
        self.click(self.anniu_loc)

    # 点击商品
    sp_loc = (By.XPATH, '/html/body/div[6]/div/div[2]/div[5]/ul/li[1]/div[2]/div[1]/a/img')

    def sp(self):
        self.click(self.sp_loc)

    # 跳转
    # 点击加入购物车
    gouwuche_loc = (By.XPATH, '/html/body/div[5]/div[2]/div[2]/div[6]/div[7]/div/a')

    def gouwuche(self):
        self.click(self.gouwuche_loc)

    # 断言活动促销/html/body/div[5]/div[2]/div[2]/div[3]/div[3]/div[2]/ul/li/i
    dy2_loc=(By.XPATH,'/html/body/div[5]/div[2]/div[2]/div[3]/div[3]/div[2]/ul/li/i')
    def dy2(self):
        return self.text(self.dy2_loc)

    # 点击查看购物车
    chakan_loc = (By.XPATH, '/html/body/div[7]/div/div[3]/a[2]')

    def chakan(self):
        self.click(self.chakan_loc)


    #点击去结算
    jiesuan_loc = (By.XPATH, '/html/body/div[3]/div[1]/div[3]/div[3]/a[1]')

    def jiesuan(self):
        self.click(self.jiesuan_loc)

    #点击提交订单
    dingdan_loc = (By.XPATH, '/html/body/div[3]/div/div[7]/div/div[2]/div[3]/a[2]')

    def dingdan(self):
        self.click(self.dingdan_loc)

    def luoji_01(self):
        self.open_url('https://www.jiuxian.com/')
        self.login()

        print(self.dy1())
        assert self.dy1() == '帐号登录'

        self.username()
        self.password()
        time.sleep(10)
        self.denglu()
        time.sleep(3)
        self.queding()
        time.sleep(3)
        self.ssk()
        self.wenzi()
        time.sleep(2)
        self.anniu()
        time.sleep(2)
        self.sp()
        time.sleep(2)
        self.qiehuan()
        time.sleep(2)

        print(self.dy2())
        assert self.dy2() == '活动促销'
        time.sleep(2)

        self.gouwuche()
        self.chakan()
        time.sleep(2)

        self.jiesuan()
        time.sleep(2)
        self.dingdan()
        time.sleep(2)
